package cn.iocoder.yudao.module.design.asyncworker.flowTask;



import com.tlcsdm.async.callback.ICallback;
import com.tlcsdm.async.callback.IWorker;
import com.tlcsdm.async.executor.timer.SystemClock;
import com.tlcsdm.async.worker.WorkResult;
import com.tlcsdm.async.wrapper.WorkerWrapper;

import java.util.Map;

/**
 * 异步发起任务通知
 * 使用方法见：https://gitee.com/jd-platform-opensource/asyncTool/blob/master/QuickStart.md
 * @author Annie
 * @ClassName FlowTaskNotifyWorker
 * @date 2023年07月29日
 * @version: 1.0
 */
public class FlowTaskCreateWorker implements IWorker<String, String>, ICallback<String, String> {


    @Override
    public void begin() {
        System.out.println(Thread.currentThread().getName() + "- start --" + System.currentTimeMillis());
    }



    /**
     * @param success
     * @param param
     * @param workResult
     */
    @Override
    public void result(boolean success, String param, WorkResult<String> workResult) {
        if (success) {
            System.out.println("callback FlowTaskCreateWorker success--" + SystemClock.now() + "----" + workResult.getResult()
                    + "-threadName:" +Thread.currentThread().getName());
        } else {
            System.err.println("callback FlowTaskCreateWorker failure--" + SystemClock.now() + "----"  + workResult.getResult()
                    + "-threadName:" +Thread.currentThread().getName());
        }
    }

    @Override
    public String action(String object, Map<String, WorkerWrapper> map) {

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "FlowTaskCreateWorker = " + SystemClock.now() + "---param = " + object + " from 1";
    }



    /**
     * @return
     */
    @Override
    public String defaultValue() {
        return "FlowTaskCreateWorker--default";
    }
}
